<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢迎访问产品运营互动中心！</title>

<script src="<s:url value="/script/jquery_last.js"/>" type="text/javascript"></script>
<script src="<s:url value="/script/formValidator.js"/>" type="text/javascript" charset="UTF-8"></script>
<script src="<s:url value="/script/formValidatorRegex.js"/>" type="text/javascript" charset="UTF-8"></script>
<script language="javascript" src="<s:url value="/script/DateTimeMask.js"/>" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function(){
	$.formValidator.initConfig({autotip:true,onerror:function(msg){alert(msg)}});
	//$("input:text[name='productReference.product.name']").formValidator({tipid:"producttip",onshow:"请选择产品"}).inputValidator({min:1,onerror:"您还没有选择产品",empty:{leftempty:false,rightempty:false,emptyerror:"产品名称两边不能有空符号"}});
	$("input:text[name='productReference.title']").formValidator({tipid:"titletip",onshow:"请输入资料标题"}).inputValidator({min:1,onerror:"您还没有输入资料标题",empty:{leftempty:false,rightempty:false,emptyerror:"标题两边不能有空符号"}});
	$("textarea[name='productReference.content']").formValidator({tipid:"contenttip",onshow:"请输入资料内容"}).inputValidator({onerror:"您还没有输入资料内容",min:1,max:300,onerror:"您输入的描述长度不能小于1和大于100字。"});
	//$("input:text[name='productReference.keyword']").formValidator({tipid:"keywordtip",onshow:"请输入资料关键字"}).inputValidator({min:1,onerror:"您还没有输入资料关键字",empty:{leftempty:false,rightempty:false,emptyerror:"关键字两边不能有空符号"}});
});
</script>
<script language="javascript" src="<s:url value="/script/ShowProcessBar.js"/>" type="text/javascript"></script>
<script type="text/javascript" src="<s:url value="/script/selfResize.js"/>"></script>

<script>
function initLoad(){
	f_iframeResize();
}
window.setInterval("initLoad()", 200);
window.setTimeout('window.parent.changeScroll()',500);
</script>
<link rel="stylesheet" href="<s:url value="/css/style_new.css"/>">
<link rel="stylesheet" href="<s:url value="/css/validator.css"/>">
<link href="<s:url value="/images/08_ccxxzx.css"/>" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" >
<table width="100%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td background="<s:url value="/images/home_4a.gif"/>">
		<table width="100%" border="0" cellspacing="0" cellpadding="0"
			align="center" bgcolor="#FFFFFF">
			<tr>
				<td width="20%" valign="top">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">
        <tr>
          <td valign="top"><br>
						<s:form action="su_saveProductReference.action"
							namespace="/security" method="post" enctype="multipart/form-data" 
							 onsubmit="setKeyWord();return (setIsPublish()&&$.formValidator.pageIsValid('1'));">
							<input type="hidden" name="productReference.id"
								value="${productReference.id}">
								<input type="hidden" name="product.id"
								value="${product.id}">
							<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0" >
								<tr>
									<td height="5">
										<table width="100%" border="0" cellspacing="0" cellpadding="0">
											<tr>
												<td width="5" height="5"><img src="<s:url value="/images/cphdzx_tab1.gif"/>" width="5" height="5" /></td>
												<td class="tdborderup"><img src="<s:url value="/images/spacer.gif"/>" width="1" height="1" /></td>
												<td width="5"><img src="<s:url value="/images/cphdzx_tab2.gif"/>" width="5" height="5" /></td>
											</tr>
										</table>
									</td>
								</tr>
								<tr>
									<td class="tdborderleftright">
									<TABLE width="100%" cellSpacing=1 cellPadding=0 align="center">
										<TR height=30>
											<TD align=left width="10%"><input type="submit" id="Submit"
												name="Submit" value="保 存"> 
												<input type="button"
												value="返 回"
												onClick="location.href='su_showProduct.action?product.id=${product.id}'">
												<input type="button"
												value="继续新增"
												onClick="location.href='<s:url value="/business/product/su_editProductReference.action"/>?product.id=${product.id }'">
											</TD>
										</TR>
									</table>
									<s:if test="#returnMsg==null">
									</s:if> <s:else>
										<TABLE width="100%" cellSpacing=1 cellPadding=0 align="center">
											<TR height=30>
												<TD align=left width="10%"><font color="red">${returnMsg}</font>
												</TD>
											</TR>
										</table>
									</s:else>
									<div class="validate"> 
									<table width="100%" border="0" cellspacing="0" cellpadding="7"
										align="center" class=tablecolor2>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right"><font color="red">*</font>所属产品：</div>
											</td>
											<td width="81%">
												<input type="hidden" name="productReference.product.id" value="${product.id}">
												<input type="text" name="productReference.product.name"
													id="product_name" value="${product.name}" readonly>
												<div id="producttip" style="width:auto"></div>
											</td>
										</tr>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right"><font color="red">*</font>资料类型：</div>
											</td>
											<td width="81%"><s:select
												name="productReference.referenceType.id" list="lRefType"
												listKey="id" listValue="name" theme="css_xhtml" /></td>
										</tr>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right"><font color="red">*</font>标&nbsp;&nbsp;&nbsp;&nbsp;题：</div>
											</td>
											<td width="81%">
											<s:textfield
												name="productReference.title" theme="css_xhtml" size="64"/>
												<div id="titletip" style="width:auto"></div></td>
										</tr>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right"><font color="red">*</font>内&nbsp;&nbsp;&nbsp;&nbsp;容：</div>
											</td>
											<td width="81%"><s:textarea
												name="productReference.content" theme="css_xhtml" cols="50" rows="6"/>
												<div id="contenttip" style="width:auto"></div></td>
										</tr>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right" class="STYLE2">附&nbsp;&nbsp;&nbsp;&nbsp;件：</div>
											</td>
											<td width="81%">
											<table width="100%" border="0" class=tablecolor2>
												<tr>
													<td width="" align="center" bgcolor="D6E3FA">附件名称</td>
													<td width="50" align="center" bgcolor="D6E3FA">是否发布</td>
													<td width="50" align="center" bgcolor="D6E3FA">删除</td>
												</tr>
												<s:iterator id="attach" value="attachs">
												<input type="hidden" name="attachIDs" value="<s:property value="id" />"/>
												<tr>
													<td>
														<s:if test="isFtp != 1">
															<a href="<s:url value="/common/showFile.action?attach.id="/><s:property value="id" />"
																target="_blank">
																<s:property value="fullName" />
															</a>
														</s:if>
														<s:if test="isFtp == 1">
															<a href="<s:url value="/common/showFtpFile.action?attach.id="/><s:property value="id" />"
																target="_blank">
																<s:property value="fullName" />
															</a>
														</s:if>
														 
													</td>
													<td align="center"><input type="checkbox"
														name="publishIDs" value="<s:property value="id" />"
 														<s:if test="isPublish==1">checked</s:if>></td>
													<td align="center"><input type="checkbox"
														name="delIDs" value="<s:property value="id" />"></td>
												</tr>
												</s:iterator>
											</table>
											<br/>
											<table width="100%" border="0" class=tablecolor2>
												<tr>
													<td width="" colspan="2" align="left" bgcolor="D6E3FA">附件上传</td>
												</tr>
												<tr>
													<td width="10px">&nbsp;</td>
													<td align="left">
														<input type="file" name="upload" size="40"/> <br/>													
														发布
														<input type="radio" name="cbIsPublish1" value="1" checked>
														不发布
														<input type="radio" name="cbIsPublish1" value="2" >
														<input type="hidden" name="isPublishs" value="0"/>
														<input type="hidden" name="isFtp" value="2"/>
														<input type="hidden" name="ftpFile" value=""/>
													</td>
												</tr>
												<tr>
													<td>&nbsp;</td>
													<td>
														<input type="file" name="upload" size="40"/> <br/>
														发布
														<input type="radio" name="cbIsPublish2" value="1" checked>
														不发布
														<input type="radio" name="cbIsPublish2" value="2" >
														<input type="hidden" name="isPublishs" value="0"/>
														<input type="hidden" name="isFtp" value="2"/>
														<input type="hidden" name="ftpFile" value=""/>
													</td>
												</tr>
												<tr>
													<td>&nbsp;</td>
													<td>
														<input type="file" name="upload" size="40"/> <br/>
														发布
														<input type="radio" name="cbIsPublish3" value="1" checked>
														不发布
														<input type="radio" name="cbIsPublish3" value="2" >
														<input type="hidden" name="isPublishs" value="0"/>
														<input type="hidden" name="isFtp" value="2"/>
														<input type="hidden" name="ftpFile" value=""/>
														 
													</td>
												</tr>
											</table>
											</td>
										</tr>
										<tr>
											<td width="19%" bgcolor="D6E3FA">
											<div align="right">发布经理：</div>
											</td>
											<td width="81%"><input type="text" id="productReference.creator"
												name="productReference.creator" readonly value="${productReference.creator}">
											<input type="button" name="selType" value="选择人员"
												onClick="selectMainPerson()" /></td>
										</tr>
										<tr style="display:none;">
											<td width="19%" bgcolor="D6E3FA">
											<div align="right">关&nbsp;键&nbsp;字：</div>
											</td>
											<td width="81%"><s:textfield
												name="productReference.keyword" theme="css_xhtml" />
												<div id="keywordtip" style="width:auto"></div></td>
										</tr>
										<input type="hidden" name="productReference.begin"
											value="<s:date name="productReference.begin" format="yyyy-MM-dd HH:mm:ss"/>">
										<input type="hidden" name="productReference.end"
											value="<s:date name="productReference.end" format="yyyy-MM-dd HH:mm:ss"/>">
									</table>
									</div>
									<TABLE width="80%" cellSpacing=1 cellPadding=0 align="center">
										<TR height=30>
											<TD align=left width="10%"><input type="submit" id="Submit1"
												name="Submit1" value="保 存"> 
												<input type="button"
												value="返 回"
												onClick="location.href='su_showProduct.action?product.id=${product.id}'">
												<input type="button"
												value="继续新增"
												onClick="location.href='<s:url value="/business/product/su_editProductReference.action"/>?product.id=${product.id }'">
											</TD>
										</TR>
									</table>
									</td>
								</tr>
								<tr>
								<td height="5">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
										<tr>
											<td width="5" height="5"><img src="<s:url value="/images/cphdzx_tab3.gif"/>" width="5" height="5" /></td>
											<td class="tdborderbottom"><img src="<s:url value="/images/spacer.gif"/>" width="1" height="1" /></td>
											<td width="5"><img src="<s:url value="/images/cphdzx_tab4.gif"/>" width="5" height="5" /></td>
										</tr>
									</table>
								</td>
							</tr>
							</table>
							</td>
					</tr>
				</table>
				</s:form> 
</body>
</html>
<script>
<!--
	function uploadFile(id) {
		window
				.open(
						'<s:url value="/common/uploadFile.action?attach.refEntity=PRODUCTREFERENCE&attach.refEntityID=" escapeAmp="false"/>'
								+ id, "uploadfile",
						"dialogWidth=420px;dialogHeight=300px");
	}
	
	function addComponent()
	{
		var uploadHTML=document.createElement("<input type='file'　name='upload'/>");
		document.getElementById("files").appendChild(uploadHTML);
		uploadHTML=document.createElement("<p/>");
		document.getElementById("files").appendChild(uploadHTML);
	}

	function selectProduct(){
	     var url='<s:url value="/xtreecheckbox/selectProduct.jsp?module=radio&date=" escapeAmp="false"/>'+'<%=System.currentTimeMillis()%>';
	    // window.prompt("",url);
			var returnData = window.showModalDialog(url, window,
					"status:no;dialogWidth:800px;dialogHeight:600px;scroll:yes;");
			if (returnData) {
				document.forms[0]["productReference.product.name"].value = returnData[1];
				document.forms[0]["productReference.product.id"].value = returnData[0];
			}
	}

	function setKeyWord(){
		var keyword=document.forms[0]['productReference.keyword'].value;
		if (keyword==""){
			var obj=document.forms[0]['productReference.referenceType.id'];
			keyword=document.forms[0]['productReference.product.name'].value
			+" "+obj.options[obj.selectedIndex].text;
			document.forms[0]['productReference.keyword'].value=keyword;
		}
	}
	
function selectMainPerson(){
    var url="<s:url value='/' escapeAmp='false'/>"+"organ/toOrganTree.action?type=&path=toPersonTree&module=radio&date=<%=System.currentTimeMillis()%>";	 
    var returnData=window.showModalDialog(url,window,"status:no;dialogWidth:650px;dialogHeight:600px;scroll:yes;");
	 if(returnData){
	 	document.all["productReference.creator"].value=returnData[1];
	 }
}
-->
</script>

<script>
//新增附件是否发布       单选处理 0 无附件   1 有附件 发布  2 有附件不发布

	function setIsPublish(){
		var isPublishs = document.getElementsByName("isPublishs");
		var cbIsPublishs1 = document.getElementsByName("cbIsPublish1");
		var cbIsPublishs2 = document.getElementsByName("cbIsPublish2");
		var cbIsPublishs3 = document.getElementsByName("cbIsPublish3");
		var uploads = document.getElementsByName("upload");
		for(i = 0; i < cbIsPublishs1.length; i++){
			if(cbIsPublishs1[i].checked == true){
		  		if(cbIsPublishs1[i].value == 1 && (uploads[0].value != null && uploads[0].value != "")){
		   			isPublishs[0].value = 1; 
		   		} else if (cbIsPublishs1[i].value == 2 && (uploads[0].value != null && uploads[0].value != "")){
		   			isPublishs[0].value = 2;
			   	} else {
			   		isPublishs[0].value = 0;
			   	}
  			}
  		}		   	
  		
		for(i = 0; i < cbIsPublishs2.length; i++){
		  	if(cbIsPublishs2[i].checked == true){
		   		if(cbIsPublishs2[i].value == 1 && (uploads[1].value != null && uploads[1].value != "")){
		   			isPublishs[1].value = 1;
		   	  	} else if (cbIsPublishs2[i].value == 2 && (uploads[1].value != null && uploads[1].value != "")){
		   			isPublishs[1].value = 2;
		   		} else {
			   		isPublishs[1].value = 0;
			   	}		   		
 			}
  		}		   		
		for(i = 0; i<cbIsPublishs3.length; i++){
			if(cbIsPublishs3[i].checked == true){
			   	if(cbIsPublishs3[i].value == 1 && (uploads[2].value != null && uploads[2].value != "")){
			   		isPublishs[2].value = 1;
		   	  	} else if (cbIsPublishs3[i].value == 2 && (uploads[2].value != null && uploads[2].value != "")){
		   			isPublishs[2].value = 2;
		   	  	} else {
			   		isPublishs[2].value = 0;
			   	}	   	  
  			}
  		}
		if(!uploadValidator()){
			return false;
		}	
		b_setDisable(document.getElementById("Submit"));
		b_setDisable(document.getElementById("Submit1"));
		return true;
	}

		//验证是否ftp上传
		function uploadValidator()
		{
			var uploads = document.getElementsByName("upload");
			var isFtps = document.getElementsByName("isFtp");
			var ftpFiles = document.getElementsByName("ftpFile");
//限制大小	以上用ftp		
			var maxFileSize = parseInt("${ftpMaxSize}");  // 1*1024*1024;
			//限制最大100M
			var maxSize = 100*1024*1024;
			//alert("maxFileSize"+maxFileSize);
			try{
				for(i=0;i<uploads.length;i++){
		   		if(uploads[i].value != null && uploads[i].value != ""){
						var image = new Image();
						image.dynsrc = uploads[i].value;
						if(image.fileSize > maxFileSize)
						{
							isFtps[i].value = "1";
							var n = i + 1;
							if(image.fileSize > maxSize)
							{
								alert("单个附件不能超过100M！");
								return false;
							}
							//alert("dynsrc您输入的第"+n+"个附件大小大于10M！请使用ftp上传！");
							ftpFiles[i].value = uploads[i].value;
						}
						else
						{
						isFtps[i].value = "0";
						}
		   		}		   		
			 }
			}catch(e)
			{
				for(i=0;i<uploads.length;i++){
					var fileSize = getFileSize(uploads[i].value);
					if(uploads[i].value != null && uploads[i].value != "" && fileSize > maxFileSize)
					{
						isFtps[i].value = "1";
						var n = i + 1;
						if(image.fileSize > maxSize)
						{
							alert("单个附件不能超过100M！");
							return false;
						}
						//alert("dynsrc您输入的第"+n+"个附件大小大于10M！请使用ftp上传！");
						ftpFiles[i].value = uploads[i].value;
					}
				}
			}
			return true;
			
		}
//获得上传文件大小 如果不是ie6 用此方式获得上传文件大小
function getFileSize (fileName) {   
  if (document.layers) {   
    if (navigator.javaEnabled()) {   
      var file = new java.io.File(fileName);   
      if (location.protocol.toLowerCase() != 'file:')   
        netscape.security.PrivilegeManager.enablePrivilege(   
        'UniversalFileRead'   
        );   
      return file.length();   
    }   
    else return -1;   
  }   
  else if (document.all) {   
    window.oldOnError = window.onerror;   
    window.onerror = function (err) {   
      if (err.indexOf('utomation') != -1) {   
        //alert('file access not possible');   
        return true;   
      }   
      else   
        return false;   
    };   
    var fso = new ActiveXObject('Scripting.FileSystemObject');   
    var file = fso.GetFile(fileName);   
    window.onerror = window.oldOnError;   
    return file.Size;   
  }   
}   

</script>